//
//  ICProfileHeaderView.m
//  ICome
//
//  Created by zhangrongwu on 16/3/15.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICProfileHeaderView.h"
#import "ICHeaderFile.h"


@implementation ICProfileHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.bgImageView = [[UIImageView alloc]initWithFrame:frame];
        self.bgImageView.layer.masksToBounds = YES;
        [self addSubview:self.bgImageView];
        //头像
        self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 85 * Level, 85 * Level)];
        self.headImageView.image = [UIImage imageNamedFromiComeSDKBundle:@"App_personal_headimg"];
        self.headImageView.userInteractionEnabled = YES;
        [self addSubview:self.headImageView];
        
        CAShapeLayer *layer = [CAShapeLayer layer];
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.headImageView.bounds];
        layer.path = path.CGPath;
        self.headImageView.layer.mask = layer;
        
        self.titleLabel = [[UILabel alloc] initWithText:@"" font:17 textColor:[UIColor whiteColor]];
        self.titleLabel.font = ICBOLDFont(20 * Level);
        [self addSubview:self.titleLabel];
        self.titleLabel.textColor = ICRGB(0xdbec98);
        self.titleLabel.userInteractionEnabled = YES;
        self.titleLabel.numberOfLines = 1;
        
        self.subTitleLbale = [[UILabel alloc] initWithText:@"" font:17 textColor:[UIColor whiteColor]];
        self.subTitleLbale.font = ICBOLDFont(18 * Level);
        [self addSubview:self.subTitleLbale];
        self.subTitleLbale.textColor = ICRGB(0xdbec98);
        self.subTitleLbale.userInteractionEnabled = YES;
        self.subTitleLbale.numberOfLines = 1;
        
        self.userFlagImage = [[UIImageView alloc]init];
        self.userFlagImage.image = [UIImage imageNamedFromiComeSDKBundle:@"App_user"];
        [self addSubview:self.userFlagImage];
        
        self.discoverButton = [[UIButton alloc] init];
        [self.discoverButton setImage:[UIImage imageNamedFromiComeSDKBundle:@"icon_detail_faxian"] forState:UIControlStateNormal];
        [self addSubview:self.discoverButton];
        
        [self layoutSubView];
    }
    return  self;
}

- (void)layoutSubView{
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom).offset(-20);
    }];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(85 * Level);
        make.left.equalTo(self.mas_left).offset(32);
        make.centerY.equalTo(self.mas_centerY);
    }];
   
    [self.discoverButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headImageView.mas_centerY);
        make.right.equalTo(self.bgImageView.mas_right).offset(-15);
    }];
    
    [self.userFlagImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.discoverButton.mas_left).offset(-5);
        make.centerY.equalTo(self.subTitleLbale.mas_centerY);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(52);
        make.centerY.equalTo(self.mas_centerY).offset(-18*Level);
        make.left.equalTo(self.headImageView.mas_right).offset(35);
        make.right.equalTo(self.discoverButton.mas_left).offset(-5);
    }];
    
    [self.subTitleLbale mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(35);
        make.centerY.equalTo(self.mas_centerY).offset(12*Level);
        make.right.equalTo(self.userFlagImage.mas_left).offset(-3);
    }];
    
}




- (void)layoutSubviews {
    [super layoutSubviews];
}
@end
